package com.jia.thumps.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jia.result.ScrollResult;
import com.jia.sms.entity.User;
import com.jia.thumps.entity.Blog;
import com.jia.thumps.service.BlogService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Blog)表控制层
 *
 * @author makejava
 * @since 2024-10-09 00:11:06
 */
@RestController
@RequestMapping("blog")
public class BlogController {
    /**
     * 服务对象
     */
    @Resource
    private BlogService blogService;

    @PostMapping
    public ResponseEntity<Boolean> insert(@RequestBody Blog blog) {
        return ResponseEntity.ok(blogService.insert(blog));
    }

    @GetMapping("{id}")
    public ResponseEntity<Blog> selectById(@PathVariable Long id) {
        return ResponseEntity.ok(blogService.queryById(id));
    }

    /**
     * 分页查询
     *
     * @param blog 筛选条件
     * @param page 分页对象
     * @return 查询结果
     * @url: http://localhost:8080/api/blog/page?current=0&size=10
     */
    @GetMapping("page")
    public ResponseEntity<Page<Blog>> queryByPage(Blog blog, Page page) {
        return ResponseEntity.ok(this.blogService.queryByPage(blog, page));
    }

    @PutMapping("like/{id}")
    public ResponseEntity<Boolean> likeBlog(@PathVariable Long id) {
        return ResponseEntity.ok(blogService.like(id));
    }

    @GetMapping("like/user/{id}")
    public ResponseEntity<List<User>> likeBlogUser(@PathVariable Long id,
                                                   @RequestParam Long top) {
        return ResponseEntity.ok(blogService.likeUser(id, top));
    }

    @GetMapping("of/follow")
    public ResponseEntity<ScrollResult> queryOwnerInbox(@RequestParam Long lastId,
                                                        @RequestParam(defaultValue = "0") Integer offset) {
        return ResponseEntity.ok(this.blogService.queryOwnerInbox(lastId, offset));
    }

}

